<?php

/**
 * 类的介绍 ：微信回复消息模板
 *
 * @param mixed
 * @return array 返回类型
 * @author      wh
 */


namespace App\Utils;


class WeChatMessageUtil
{

    /**
     * 回复文本消息
     * @param $object
     * @param $content
     * @return array
     */
    public static function transmitText($object, $content)
    {
        $xmlTpl = "<xml>
    <ToUserName><![CDATA[%s]]></ToUserName>
    <FromUserName><![CDATA[%s]]></FromUserName>
    <CreateTime><![CDATA[%s]]></CreateTime>
    <MsgType><![CDATA[text]]></MsgType>
    <Content><![CDATA[%s]]></Content>
</xml>";
        return sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), $content);

    }

    /**
     * 回复图文消息
     * @param $object
     * @param $title
     * @param $desc
     * @param $piurl
     * @param $url
     * @return string
     */
    public static function transmitNews($object, $title, $desc, $piurl, $url)
    {
        $xmlTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>![CDATA[%s]]</CreateTime>
                <MsgType><![CDATA[news]]></MsgType>
                <ArticleCount>1</ArticleCount>
                <Articles>
                <item>
                <Title><![CDATA[%s]]></Title>
                <Description><![CDATA[%s]]></Description>
                <PicUrl><![CDATA[%s]]></PicUrl>
                <Url><![CDATA[%s]]></Url>
                </item>
                </Articles>
                </xml>";
        return sprintf($xmlTpl, $object->FromUserName, $object->ToUserName, time(), $title, $desc, $piurl, $url);
    }

}
